<?php
	//includes
	require_once 'includes.php';

	//delete all
//	DB::ExecuteSQL("
//		DELETE FROM t_beers;
//	");
	
	$startTime = microtime() + time();
	
	$beerDB = new BeerDB();
	$products = $beerDB->GetSavedBeerURLs($_GET['offset'], $_GET['number']);
	
	$result = array('success' => 0, 'fail' => 0);
	
	//saves beers
	foreach ($products as $url)
	{
		//beer item
		$beerItem = $beerDB->GetBeerItem($url['url'], $url['id']);
		
		//URL id
		$beerItem->urlId = $url['id'];
		
		//saves the beer into DB
		$saveResult = $beerItem->Save();
		
		//stats
		if ($saveResult)
		{
			$result['success']++;
		}
		else 
		{
			$result['fail']++;
		}		
	}

	$endTime = microtime() + time();
	
	//totals
	$resultTime = $endTime - $startTime;
	echo "Total time: $resultTime; Success: {$result['success']}; Fail: {$result['fail']}; ";		
	
?>